#include <sysdep.h>
#include <stdarg.h>

static const char *log_hlv_str(uint8_t high_lv)
{
	switch (high_lv) {
	case LOG_NUM:
		return LOG_NUM_STR;
	case LOG_SHELL:
		return LOG_SHELL_STR;
	case LOG_MAIN:
		return LOG_MAIN_STR;
	default:
		return "undefined";
	}
}

void calc_log(int level, const char *format, ...)
{
	va_list args;
	FILE *stream = stderr;
	const char *prefix;

	switch (LOG_L_BYTE(level)) {
	case LOG_INFO:
		stream = stdout;
		prefix = "info";
		break;
	case LOG_WARN:
		prefix = "warn";
		break;
	case LOG_ERR:
		prefix = "err";
		break;
	case LOG_DEBUG:
		stream = stdout;
		prefix = "debug";
		break;
	default:
		prefix = "unknown";
		break;
	}

	fprintf(stream, "[%s] ", log_hlv_str((uint8_t)LOG_H_BYTE(level)));

	va_start(args, format);
	vfprintf(stream, format, args);
	va_end(args);

	fprintf(stream, "\r\n");
}
